package com.joey.jvm.example.constantpool;

/**
 * @Author hyy
 **/
public class ConstantPoolExample {

    public static void main(String[] args) {
        //存放在方法区中的常量池
        String s1 = "abc";
        String s2 = "abc";
        System.out.println(s1 == s2);
        /**
         * 引用对象-->分配到java堆中
         */
        //存放在堆中
        String s3 = new String("abc");
        String s4 = new String("abc");
        String s5 = s3.intern();
        System.out.println(s1 == s3);
        System.out.println(s3 == s4);
        System.out.println(s5 == s1);

        //字符串拼接产生对象
        String s6 = "ABC"+s1;
        String s7 = "ABC"+s2;
        String s8 = "ABCabc";
        System.out.println(s6 == s7);//false
        System.out.println(s6 == s8);//false
        System.out.println(s6.intern() == s8);//true

    }
}
